<?php

namespace app\app\controller;

use app\common\model\BasicConfig;
use think\Controller;

class Config extends Common
{
    /**
     * 时间戳获取
     * @Author   chenjianghui
     * @DateTime 2018-08-09T09:52:56+0800
     * @return   [type]                   [description]
     */
    public function getTime()
    {
        renderJson('时间戳', 1, ['time' => time()]);
    }

    /**
     * 注册协议
     * @Author   chenjianghui
     * @DateTime 2018-08-09T09:52:48+0800
     * @return   [type]                   [description]
     */
    public function getAgreement()
    {
        $type = request()->param('type');
        $where['type'] = 'client';
        switch ($type) {
            case 'register_agreement':
                $where['key'] = $type;
                break;
            case 'user_agreement':
                $where['key'] = $type;
                break;
            default:
                renderJson('请正确填写类型',0);
                break;
        }
        $basic = BasicConfig::where($where)->find();
        if ($basic) {
            $data['agreement'] = $basic->value ?: '';
            renderJson('基本信息', 1, $data);
        }
        renderJson('基本信息', 0);
    }

    /**
     * 关于我们
     * @Author   chenjianghui
     * @DateTime 2018-08-10T17:03:47+0800
     * @return   [type]                   [description]
     */
    public function aboutUs()
    {
        $where['type'] = 'client';
        $where['key'] = ['in',['telephone','company']];
        $basic = BasicConfig::where($where)->select();
        if ($basic) {
            foreach ($basic as $key => $value) {
                switch ($value->key) {
                    case 'telephone':
                        $data['telephone'] = $value->value ?: '';
                        break;
                    case 'company':
                        $data['company'] = $value->value ?: '';
                        break;
                    default:
                        break;
                }
            }
            renderJson('关于我们', 1, $data);
        }
         renderJson('关于我们', 0);
    }


    /**
     * android  版本更新
     * @Author   chenjianghui
     * @DateTime 2018-08-09T18:58:03+0800
     * @return   [type]                   [description]
     */
    public function androidUpdateVer()
    {
        $result = BasicConfig::getVersionConfig('android');
        renderJson('成功', 1, $result);
    }

    /**
     * ios 版本更新
     * @Author   chenjianghui
     * @DateTime 2018-08-09T18:58:40+0800
     * @return   [type]                   [description]
     */
    public function iosUpdateVer()
    {
        $result = BasicConfig::getVersionConfig('ios');
        renderJson('成功', 1, $result);
    }
}
